package com.wang.service.impl;

import com.aaa.entity.BBusinessInfo;
import com.aaa.entity.UUserInfo;
import com.aaa.security.util.WebUtils;
import com.aaa.util.JwtUtil;
import com.aaa.vo.Result;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wang.mapper.BBusinessInfoMapper;
import com.wang.mapper.UUserInfoMapper;
import com.wang.service.openfeign.UpdataLoad;
import com.wang.service.BBusinessInfoService;
import com.wang.vo.CollectibleGoodsVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;
import java.util.Map;

/**
 *这里面有回显值，我们只需要判断它的登录是啥人即可
 */
@Service
public class BBusinessInfoServiceImpl extends ServiceImpl<BBusinessInfoMapper, BBusinessInfo>
        implements BBusinessInfoService {

    @Autowired
    private BBusinessInfoMapper mapper;
    @Autowired
    private UUserInfoMapper uUserInfoMapper;
    @Autowired
    private UpdataLoad updataLoad;
      @Override
    public Result Echo() {
        String token = WebUtils.getRequest().getHeader("token");
        Map<String, Object> map = JwtUtil.getTokenChaim(token);
        String username = (String) map.get("username");
        String loginType = (String) map.get("loginType");
          if ("USER_PHONE".equals(loginType)) {
            LambdaQueryWrapper<UUserInfo> wrapper = new LambdaQueryWrapper<>();
            wrapper.eq(UUserInfo::getTelephone, username);
            UUserInfo uUserInfo = uUserInfoMapper.selectOne(wrapper);
            return new Result(2000, "success", uUserInfo);
        } else {
            LambdaQueryWrapper<BBusinessInfo> wrapper = new LambdaQueryWrapper<>();
            wrapper.eq(BBusinessInfo::getSname, username);
            BBusinessInfo bBusinessInfo = mapper.selectOne(wrapper);
            return new Result(2000, "success", bBusinessInfo);
        }
    }
    @Autowired
    private BBusinessInfoService bBusinessInfoService;
    @Override
    public Result update( MultipartFile file) {
        Result updateload = updataLoad.updateload(file);
        return  new Result(200, "success", updateload);
    }

    @Override
    public Result findCollectByphone(String phone) {
        List<BBusinessInfo> collectByphone = mapper.findCollectByphone(phone);
        return new Result(2000,"查询成功",collectByphone);
    }

    @Override
    public Result unfollow(String bid, String telephone) {

        int unfollow = mapper.unfollow(bid, telephone);
        if (unfollow!=0){
            return new Result(2000,"取关成功");
        }
        return new Result(5000,"取关失败");
    }

    @Override
    public Result CollectibleGoods(String phone) {
        List<CollectibleGoodsVo> collectibleGoodsVos = mapper.CollectibleGoods(phone);
        return new Result(2000,"查询成功",collectibleGoodsVos);
    }

    @Override
    public Result unfollowCollectibleGoods(String gid, String telephone) {
        int i = mapper.unfollowCollectibleGoods(gid, telephone);
        if (i!=0){
            return new Result(2000,"取关成功");
        }
        return new Result(5000,"取关失败");
    }


}




